import React, {Component} from 'react';
import {Map} from 'immutable';

import {Pagination, Row, Col} from 'antd';

import noop from 'util/noop';


export default class Pages extends Component {
    static defaultProps = {
        pagination: Map(),
        changePageNum: noop,
        changePageSize: noop
    }


    render() {
        const {pagination} = this.props;

        return (
            <Row className="pagination-retail mb40">
                <Col span="7"/>
                <Col span="17">
                    <Pagination size="default"
                                className="pull-right"
                                current={pagination.get('pageNum')}
                                total={pagination.get('totalCount')}
                                pageSize={pagination.get('pageSize')}
                                pageSizeOptions={['12', '24', '36', '48']}
                                showQuickJumper={true}
                                showSizeChanger={true}
                                showTotal={(total, range) => `共${total}条`}
                                onChange={(page)=>this.changePageNum(page)}
                                onShowSizeChange={(current, size)=>this.changePageSize(current, size)}/>
                </Col>
            </Row>
        )
    }


    /**
     * 点击分页
     * @param pageNum
     */
    changePageNum(pageNum) {
        this.props.changePageNum(pageNum);
    }


    /**
     * 修改pageSize
     * @param pageNum
     * @param pageSie
     */
    changePageSize(pageNum, pageSie) {
        this.props.changePageSize(pageNum, pageSie);
    }
}